package com.shengyin.ec.service.alliance;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.alliance.AllianceDao;
import com.shengyin.ec.model.entity.Company;

@Service("allianceService")
public class AllianceServiceImpl implements AllianceService {
	
	@Autowired
	AllianceDao allianceDao;

	@Override
	public List<Company> getCompanyList() {
		return allianceDao.loadAll();
	}

	@Override
	public void createCompany(Company company) {
		allianceDao.save(company);
	}

	@Override
	public void removeCompanyById(long id) {
		allianceDao.deleteByKey(id);
	}

	@Override
	public void modifyCompany(Company company) {
		Company company1= allianceDao.get(company.getId());
		allianceDao.update(company1);
	}

	public List<Company> getCompany(int status){
		return allianceDao.getCompanyList(status);
	}

	@Override
	public Company getCompanyById(long id) {
		return allianceDao.get(id);	
	}

	@Override
	public void passCompanyById(long id,int status) {
		Company company  = allianceDao.get(id);
		company.setStatus(status);
		allianceDao.update(company);
	}

	@Override
	public void rejectCompanyById(long id,int status) {
		Company company  = allianceDao.get(id);
		company.setStatus(status);
		allianceDao.update(company);
		
	}

	@Override
	public void cancelCompanyById(long id,int status) {
		Company company  = allianceDao.get(id);
		company.setStatus(status);
		allianceDao.update(company);
		
	}

	
	@Override
	public boolean checkCompanyUser(String username, String pwd){
		boolean ret = allianceDao.checkCompanyUser(username, pwd);
		return ret;
	}
	
	@Override
	public List<Company> getCompanyByName(String username){
		List<Company> list = allianceDao.getCompanyByName(username);
		return list;
	}

	//add by wql 2012-3-20
	@Override
	public List<Company> getCompanyList(int offset,int pagesize){
		return allianceDao.getCompanyList(offset,pagesize);
	}
    
	@Override
	public List<Company> getCompany(int status,int offset,int pagesize){
		return allianceDao.getCompany(status,offset,pagesize);
	}

	@Override
	public Long getTotal(){
		return allianceDao.getTotal();
	}
	
	@Override
	public void deleteSelectedAlliance(String[] ids) {
		if(ids!=null){
			Long[] idsl=new Long[ids.length];
			for(int i=0;i<ids.length;i++){
				if(ids[i]!=null||!ids[i].isEmpty()){
					idsl[i]=Long.valueOf(ids[i].trim());
				}
				
			}
			allianceDao.deleteSelectedAlliance(idsl);
			}
	}
	
	@Override
	public void updateAlliance(Company company){
		allianceDao.updateAlliance(company);
	}
	
	@Override
	public List<Company> getCompanyListByCity(){
		return allianceDao.getCompanyListByCity();
	}
	@Override
	public List<Company> getCompanyListByNature(){
		return allianceDao.getCompanyListByNature();
	}
	@Override
	public List<Company> getCompanyListByEmployee(){
		return allianceDao.getCompanyListByEmployee();
	}
	@Override
	public List<Company> getAllianceCompanyList(){
		return allianceDao.getAllianceCompanyList();
	}
	
	
	public List<Company> getCompanyListByName(String keyword,int offset,int pageSize){
		
		return allianceDao.getCompanyListByName(keyword,offset,pageSize);
	}
	
    public List<Company> getCompanyListByName(String keyword){
		
    	return allianceDao.getCompanyListByName(keyword);
	}
}
